﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
using Model;
using ExtAspNet;
namespace HealthSystem
{
    public partial class DistrictAdminAll : BasePage
    {
        HW_Manger_Admin_UserManager manager = new HW_Manger_Admin_UserManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }
        }
        public void BindGrid()
        {
            System.Data.DataTable list = new System.Data.DataTable();
                int count = 0;
                list = manager.GetDistrictAdmin(Gird1.PageIndex, Gird1.PageSize, out count,CustomerProfile.DistrictId);
                this.Gird1.DataSource = list;
                this.Gird1.DataBind();
        }
        public void Window1_Close(object sender, EventArgs e)
        {
            BindGrid();
        }
        protected void Grid1_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
        {
            try
            {
                string username = Gird1.Rows[e.RowIndex].DataKeys[2].ToString();
                //if (e.CommandName == "delete")
                //{
                //    manager.DeleteById(username);
                //    BindGrid();

                //}
                if (e.CommandName == "reset")
                {
                    //重置密码
                    HW_Manger_Admin_UserManager adminUserManager = new HW_Manger_Admin_UserManager();
                    //HW_OrgUserManager orgUserManager = new HW_OrgUserManager();
                    //HW_Manger_Admin_User managerUser = adminUserManager.GetById(username);
                    string pass = System.Configuration.ConfigurationManager.AppSettings["default"].ToString();
                    adminUserManager.ResetPassWord(username, pass);
                    Alert.Show("密码重置成功");
                    //BindGrid();
                }
            }
            catch
            {
                Alert.Show("操作失败!");
            }
        }
        public void SearchClick(object sender, EventArgs e)
        {
            try
            {
                Search(searchbox.Text.Trim());
            }
            catch
            {
                Alert.Show("查询错误");
            }
        }
        public void Search(string searchString)
        {
            string DistrictId = CustomerProfile.DistrictId;
            int count = 0;
            System.Data.DataTable list = manager.Search(Gird1.PageIndex, Gird1.PageSize, out count, DistrictId, searchString,"1003");
            Gird1.RecordCount = count;
            this.Gird1.DataSource = list;
            this.Gird1.DataBind();
            this.actionbt.Text = "search";
        }
    }
}